package com.roc.web.action.terminal;

import java.util.ArrayList;
import java.util.List;

import com.roc.page.BaseSearchCondition;
import com.roc.page.WhereHQLFieldBean;
import com.roc.util.Constance;

public class TerminalSnBatchQuerySearchCondition extends BaseSearchCondition  {

	private String orgCode;
	private String agentId;
	private String agentName;
	private String posBrand;  //品牌

	private String  batchNo; // 批次号
	private String  beginSerialNum; // 开始sn字段
	private String  endSerialNum; // 结束sn字段

	private String obj;//代理商id
	
	
	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getOrderPartOfHQL()
	 */
	@Override
	protected String getOrderPartOfHQL() {
		// TODO Auto-generated method stub
		
		return " order by b.dt_create desc";
	}

	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getRowCountHQL()
	 */
	@Override
	protected String getRowCountHQL() {//,OrgBean o  t.orgCode = o.org_code
		StringBuffer sb=new StringBuffer();
		sb.append(" SELECT COUNT(1) ");
		sb.append(" FROM YJ_POS_BATCH b ");
		sb.append(" , T_OPERATORS o ");
		
		sb.append(" where  b.agent_id = o.id ");
	//	System.out.println(sb.toString());
		return sb.toString();
	}

	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getSearchHQL()
	 */
	@Override
	protected String getSearchHQL() {
		StringBuffer sb=new StringBuffer();
		sb.append(" SELECT b.BATCH_NO , b.BEGIN_SERIAL_NUM , b.END_SERIAL_NUM , b.NUMS , b.REMARK , b.ORG_CODE , b.OPERATOR_NO , " 
				+ " b.OPERATOR_ID , b.AGENT_ID , b.DT_CREATE , 	b.DT_LASTMOD , b.POS_BRAND  ,o.REAL_NAME ");
		sb.append(" FROM YJ_POS_BATCH b ");
		sb.append(" , T_OPERATORS o ");
		
		sb.append(" where b.agent_id = o.id ");
		
		return sb.toString(); 
	}

	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getWhereHQLFieldBeanList()
	 */
	@Override
	protected List<WhereHQLFieldBean> getWhereHQLFieldBeanList() {
		List<WhereHQLFieldBean> filedBeanList = new ArrayList<WhereHQLFieldBean>();

		
		if (Constance.isNotEmpty(orgCode)) {
			filedBeanList.add(new WhereHQLFieldBean("b.org_code", orgCode.trim(), "=", false));
		}

		if (Constance.isNotEmpty(batchNo)) {
			filedBeanList.add(new WhereHQLFieldBean("b.BATCH_NO", batchNo.trim(), "=", false));
		}
		if (Constance.isNotEmpty(posBrand) && !posBrand.equals("-1")) {
			filedBeanList.add(new WhereHQLFieldBean("b.pos_brand", posBrand, "=", false));
		}
		if (Constance.isNotEmpty(agentId)) {
			filedBeanList.add(new WhereHQLFieldBean("b.agent_id", agentId.trim(), "=", false));
		}
		if (Constance.isNotEmpty(agentName)) {
			filedBeanList.add(new WhereHQLFieldBean("o.REAL_NAME", agentName.trim(), "=", false));
		}

		if (Constance.isNotEmpty(beginSerialNum) && !beginSerialNum.equals("")) {
			filedBeanList.add(new WhereHQLFieldBean("b.BEGIN_SERIAL_NUM", beginSerialNum.trim(), "=", false));
		}
		if (Constance.isNotEmpty(endSerialNum) && !endSerialNum.equals("")) {
			filedBeanList.add(new WhereHQLFieldBean("b.END_SERIAL_NUM", endSerialNum.trim(), "=", false));
		}
		return filedBeanList;
	}


	public String getBatchNo() {
		return batchNo;
	}

	public void setBatchNo(String batchNo) {
		this.batchNo = batchNo;
	}

	public String getOrgCode() {
		return orgCode;
	}

	public void setOrgCode(String orgCode) {
		this.orgCode = orgCode;
	}

	public String getPosBrand() {
		return posBrand;
	}

	public void setPosBrand(String posBrand) {
		this.posBrand = posBrand;
	}

	public String getAgentId() {
		return agentId;
	}

	public void setAgentId(String agentId) {
		this.agentId = agentId;
	}

	public String getObj() {
		return obj;
	}

	public void setObj(String obj) {
		this.obj = obj;
	}

	public String getBeginSerialNum() {
		return beginSerialNum;
	}

	public void setBeginSerialNum(String beginSerialNum) {
		this.beginSerialNum = beginSerialNum;
	}

	public String getEndSerialNum() {
		return endSerialNum;
	}

	public void setEndSerialNum(String endSerialNum) {
		this.endSerialNum = endSerialNum;
	}

	public String getAgentName() {
		return agentName;
	}

	public void setAgentName(String agentName) {
		this.agentName = agentName;
	}

}
